import java.util.Arrays;

/**
 * 1828. 统计一个圆中点的数目
 * https://leetcode-cn.com/problems/queries-on-number-of-points-inside-a-circle/
 */
public class Solutions_1828 {
    public static void main(String[] args) {
        int[][] points = {{1, 3}, {3, 3}, {5, 3}, {2, 2}};
        int[][] queries = {{2, 3, 1}, {4, 3, 1}, {1, 1, 2}};  // output: {3, 2, 2}

//        int[][] points = {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}};
//        int[][] queries = {{1, 2, 2}, {2, 2, 2}, {4, 3, 2}, {4, 3, 3}};  // output: {2, 3, 2, 4}

        int[] result = countPoints(points, queries);
        System.out.println(Arrays.toString(result));
    }

    /**
     * 解题思路：暴力法 + 数学计算
     * 距离公式：若一个圆的圆心为 [x,y]，半径为 r，
     * 判断点 [x1,y1] 是否在圆内或圆周上，计算公式：r^2 <= (x-x1)^2 + (y-y1)^2
     */
    public static int[] countPoints(int[][] points, int[][] queries) {
        int len = queries.length;
        int[] res = new int[len];
        for (int i = 0; i < len; i++) {
            int r = queries[i][2];
            int x = queries[i][0];
            int y = queries[i][1];
            for (int[] point : points) {
                int j = point[0] - x;
                int k = point[1] - y;
                if (j * j + k * k <= r * r) {
                    res[i] ++;
                }
            }
        }
        return res;
    }
}
